package com.SouthernWall_404.AgeDust.Common.Event;

import com.SouthernWall_404.AgeDust.Common.API.Capability.PlayerPersonalityProvider;
import net.minecraft.world.entity.player.Player;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;

public class OnPlayerCloneEvent {

    @SubscribeEvent
    public static void onPlayerClone(PlayerEvent.Clone event) {
            Player original = event.getOriginal();
            Player newPlayer = event.getEntity();

            // 复活时复制能力数据
            original.reviveCaps(); // 重新激活死亡实体的Capability

            original.getCapability(PlayerPersonalityProvider.PLAYER_PERSONALITY_CAPABILITY).ifPresent(oldCap -> {
                newPlayer.getCapability(PlayerPersonalityProvider.PLAYER_PERSONALITY_CAPABILITY).ifPresent(newCap -> {
                    // 实现数据复制方法
                    newCap.copyfrom(oldCap);
                });
            });

            original.invalidateCaps(); // 再次失效旧实体
        }
}
